/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/itframe">itframe</a> All rights reserved.
 */
package com.rise.itframe.modules.inv.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rise.itframe.common.persistence.Page;
import com.rise.itframe.common.service.CrudService;
import com.rise.itframe.modules.inv.dao.InvConfDao;
import com.rise.itframe.modules.inv.dao.InvInfoDao;
import com.rise.itframe.modules.inv.entity.InvInfo;
import com.rise.itframe.modules.sys.utils.UserUtils;

/**
 * 发票登记信息Service
 * @author ming
 * @version 2017-12-31
 */
@Service
@Transactional(readOnly = true)
public class InvInfoService extends CrudService<InvInfoDao, InvInfo> {
    @Autowired
    private InvInfoDao invInfoDao;
    @Autowired
    private InvConfDao invConfDao;
    @Override
    public InvInfo get(String id) {
        return super.get(id);
    }

    @Override
    public List<InvInfo> findList(InvInfo invInfo) {
        // 生成数据权限过滤条件（dsf为dataScopeFilter的简写，在xml中使用 ${sqlMap.dsf}调用权限SQL）
        invInfo.getSqlMap().put("dsf", dataScopeFilter(invInfo.getCurrentUser(), "o", "b"));
        return super.findList(invInfo);
    }

    public List<InvInfo> findListByPlateNo(InvInfo invInfo,Integer plateNoInterval) {
        return invInfoDao.findListByPlateNo(invInfo,plateNoInterval);
    }

    public List<InvInfo> findListByDept(InvInfo invInfo) {
        return invInfoDao.findListByDept(invInfo);
    }

    public List<InvInfo> findListByTransact(InvInfo invInfo) {
        return invInfoDao.findListByTransact(invInfo);
    }

    /**
     * 查询相似开票列表
     * @param invInfo
     * @return
     */
    public List<InvInfo> findSimilarList(InvInfo invInfo) {
        invInfo.setCreateBy(UserUtils.getUser());
        return invInfoDao.findSimilarList(invInfo);
    }

    @Override
    public Page<InvInfo> findPage(Page<InvInfo> page, InvInfo invInfo) {
        // 生成数据权限过滤条件（dsf为dataScopeFilter的简写，在xml中使用 ${sqlMap.dsf}调用权限SQL）
        if ("9".equals(invInfo.getOperateFlag())) {// 统计查询
            invInfo.getSqlMap().put("dsf", dataScopeFilter(invInfo.getCurrentUser(), "o", "b"));
        } else {
            invInfo.getSqlMap().put("dsf", " and a.create_by='" + UserUtils.getUser().getId() + "'");
        }
        return super.findPage(page, invInfo);
    }

    @Override
    @Transactional(readOnly = false)
    public void save(InvInfo invInfo) {
        // 校验发票名称是否正确
        //        InvConf conf = invConfDao.getByInvDeptName(invInfo.getInvDeptName());
        //        if (conf != null) {
        super.save(invInfo);
        //        }
    }

    @Override
    @Transactional(readOnly = false)
    public void delete(InvInfo invInfo) {
        super.delete(invInfo);
    }

    /**
     * 查询所有开票单位
     * @return
     */
    public List<String> getAllInvDeptNames(InvInfo invInfo) {
        return invInfoDao.getAllInvDeptNames(invInfo);
    }

    /**
     * 查询当天该开票单位开票次数
     * @param invInfo
     */
    public Integer getInvNums(InvInfo invInfo) {
        return invInfoDao.getInvNums(invInfo);
    }

    public Map<String, String> findListSum(InvInfo invInfo) {
        return invInfoDao.findListSum(invInfo);
    }

}